﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows.Data;

namespace VisualWix
{
    [ValueConversion(typeof(Item), typeof(ContextMenu))]
    public class ItemToContextMenuConverter : IValueConverter
    {
        public static ContextMenu RootFolderContextMenu;
        public static ContextMenu FolderContextMenu;
        public static ContextMenu FileContextMenu;
        public static ContextMenu ShortcutRootFolderContextMenu;
        public static ContextMenu ShortcutFolderContextMenu;

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            ContextMenu menu = null;
            Item item = value as Item;

            if (item != null && item.IsContextMenuEnabled)
            {
                switch (item.HierarchyType)
                {
                    case HierarchyType.RootFolder:
                        menu = RootFolderContextMenu;
                        break;
                    case HierarchyType.SystemFolder:
                        menu = FolderContextMenu;
                        break;
                    case HierarchyType.Folder:
                        menu = FolderContextMenu;
                        break;
                    case HierarchyType.File:
                        menu = FileContextMenu;
                        break;
                    case HierarchyType.ShortcutRootFolder:
                        menu = ShortcutRootFolderContextMenu;
                        break;
                    case HierarchyType.ShortcutFolder:
                    case HierarchyType.SystemShortcutFolder:
                        menu = ShortcutFolderContextMenu;
                        break;
                    case HierarchyType.Shortcut:
                        menu = FileContextMenu;
                        break;
                    default:
                        menu = null;
                        break;
                }
                Trace.WriteLine(string.Format("Name: {0} Type {1}", item.Name, item.HierarchyType));
            }
            return menu;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new Exception("The method or operation is not implemented.");
        }
    }
}
